/*
 * ASTAbstractNode.h
 *
 *  Created on: 2010-6-3
 *      Author: Guobc
 */

#ifndef ASTABSTRACTNODE_H_
#define ASTABSTRACTNODE_H_

#include "ASTNode.h"
#include "ASTNodeList.h"
#include "ASTDom.h"
using namespace std;

namespace HA {

class ASTAbstractNode: public HA::ASTNode {
public:

	ASTAbstractNode();

	ASTAbstractNode(ASTDom* document, int start, int end);

	/**
	 * Sets string contents of the node
	 * @param text The new text for the node
	 */
	inline void setText(const string& text) {

	}

	/**
	 * Returns the text of the node.
	 * @return The contents of the string or remark node, and in the case of
	 * a tag, the contents of the tag less the enclosing angle brackets.
	 */
	inline string getText() {
		return "";
	}

	/**
	 * Sets the starting position.
	 * @param start The new start position.
	 */
	inline void setStartLine(int start) {
		startLine = start;
	}

	/**
	 * Gets the starting position.
	 * @return This is character(not byte) offset of this node in the document.
	 */
	inline int getStartLine() const {
		return startLine;
	}

	/**
	 * Sets the ending position.
	 * @param end The new end position.
	 */
	inline void setEndLine(int end) {
		endLine = end;
	}

	/**
	 * Gets the ending position.
	 * @return This is character(not byte) offset of character following this node
	 * in the document.
	 */
	inline int getEndLine() const {
		return endLine;
	}

	/**
	 * Sets document this node came from.
	 */
	inline void setDocument(ASTDom* document) {
		mDocument = document;
	}

	inline ASTDom* getDocument() const {
		return mDocument;
	}

	/**
	 * Sets the parent of this node.
	 * @param parent The parent of this node.
	 */
	inline void setParent(ASTNode* parent) {
		mParent = parent;
	}

	/**
	 * Gets the parent of this node.
	 * @return The parent of this node, if it's been set, NULL otherwise.
	 */
	inline ASTNode* getParent() const {
		return mParent;
	}

	/**
	 * Append a child to this node.
	 * @param child The child node of this node.
	 */
	inline void appendChild(ASTNode* child) {
		children.append(child);
	}

	/*/
	 * Gets the first child of this node.
	 * @return The first child in the list of children contained by this node.
	 */
	inline ASTNode* getFirstChild() const {
		return children.item(0);
	}

	/**
	 * Gets the last child of this node.
	 * @return The last child in the last of children contained by this node.
	 */
	inline ASTNode* getLastChild() const {
		return children.item(children.size() - 1);
	}

	/**
	 * Gets the previous sibling to this node
	 * @return The previous sibling to this node if one exists.
	 */
	ASTNode* getPreviousSibling();

	/**
	 * Gets the next sibling to this node.
	 * @return The next sibling to this node if none exists.
	 */
	ASTNode* getNextSibling();

	/**
	 * Gets children of this node.
	 * @return The list of children contained by this node if has one or more child.
	 */
	inline ASTNodeList getChildren() const {
		return children;
	}

	/**
	 * Test whether this node has children
	 */
	inline bool hasChildren() const {
		return children.size() == 0;
	}

	/**
	 * Test whether two nodes are equal.
	 * @param node The node been tested.
	 */
	inline bool operator==(ASTNode& node) {
		return this->toHTML() == node.toHTML();
	}

	/**
	 * Return the HTML for this node.
	 * This should be the sequence of characters that were encountered by
	 * the parser that caused this node to be created. Where this breaks down is
	 * where broken nodes (tags and remarks) have been encountered and fixed.
	 * Applications reproducing html can use this method on nodes which are to
	 * be used or transferred as they were received or created.
	 * @return The sequence of characters that would cause this node
	 * to be returned by the parser or lexer.
	 */
	inline string toHTML(){
		return "";
	}

	/**
	 * Allow creating an instance of this node.
	 * @return A new instance of this node.
	 */
	inline ASTNode* newInstance() const {
		return NULL;
	}

	~ASTAbstractNode();

protected:
	ASTDom* mDocument;
	ASTNode* mParent;
	ASTNodeList children;
	int startLine;
	int endLine;
};
}
#endif /* ASTABSTRACTNODE_H_ */
